/*
 *  Copyright (C) 2010 takaji
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * InsertTransactionStep.java
 *
 * Created on Jan 25, 2010, 12:04:01 AM
 */
package dakside.hacc.modules.databridge.dataagent;

import dakside.hacc.core.models.Transaction;
import org.dakside.duck.dakwizard.AbstractWizardStep;
import org.dakside.duck.helpers.SwingHelper;
import org.dakside.utils.ResourceCentre;
import java.util.logging.Logger;

/**
 *
 * @author takaji
 */
public class InsertTransactionStep extends AbstractWizardStep<ImportLoaderWizardModel> {

    private static final Logger logger = Logger.getLogger(InsertTransactionStep.class.getName());
    private final ResourceCentre rc = ResourceCentre.getInstance(this);

    /** Creates new form InsertTransactionStep */
    public InsertTransactionStep(ImportLoaderWizardModel model) {
        super(model, true);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnSave = new javax.swing.JButton();

        btnSave.setText("Save to database");
        btnSave.setName("btnSave"); // NOI18N
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnSave, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnSave)
                .addContainerGap(261, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        if (getWizardModel().getModelset() instanceof Transaction[]) {
            Transaction[] trxs = (Transaction[]) getWizardModel().getModelset();
            int records = DataAgencyController.save(trxs);

            //notify user
            SwingHelper.alert(rc.getMessage("saved", new Object[]{records}), rc.getString("saved_header"));
        }
    }//GEN-LAST:event_btnSaveActionPerformed

    @Override
    public boolean isCancellable() {
        return true;
    }

    @Override
    public boolean isFinishable() {
        return true;
    }

    @Override
    public boolean canGoNext() {
        return false;
    }

    @Override
    public boolean canGoBack() {
        return true;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSave;
    // End of variables declaration//GEN-END:variables
}
